{extend name="public:base"/}


{block name="title"}编辑物流配置{/block}
{block name="style"}{/block}

{block name="main"}

<section class="content" xmlns="http://www.w3.org/1999/html">
    <div class="row">

        <div class="col-md-12">

            <div class="row">
                <div class="col-lg-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">编辑物流配置</h3>
                        </div>
                        <form  id="pt_form" method="post">
                            <div class="box-body">

                                <input type="hidden" name="shipping_area_id" value="<?=$model['shipping_area_id']?>" ?>
                                <div class="clearfix"></div>

     
                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="shipping_area_name" class="control-label Validform_label" >配送区域名称</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="shipping_area_name" class="form-control" name="shipping_area_name" placeholder="请输入配送区域名称" value="<?=$model['shipping_area_name']?>" datatype="s2-150" ignore="ignore"  errormsg="配送区域名称超出长度范围">
                                        <div class="help-block"></div>
                                    </div>
                                </div>


                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="shipping_area_name" class="control-label Validform_label" >首重                       <select name="config[first_weight]">
                                            <option value="500"  selected="selected">500</option>
                                            <option value="1000">1000</option>
                                            <option value="1500">1500</option>
                                            <option value="2000">2000</option>
                                            <option value="2500">2500</option>
                                            <option value="3000">3000</option>
                                            <option value="3500">3500</option>
                                            <option value="4000">4000</option>
                                            <option value="4500">4500</option>
                                            <option value="5000">5000</option>
                                            <option value="5500">5500</option>
                                            <option value="6000">6000</option>
                                            <option value="6500">6500</option>
                                            <option value="7000">7000</option>
                                            <option value="7500">7500</option>
                                        </select>
                                            克以内费用</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="config[money]" class="form-control" name="config[money]" placeholder="请输入首重费用" value="<?=$model['config']['money']?>" datatype="n" errormsg="首重费用必须是数字类型">
                                        <div class="help-block">单位：元</div>
                                    </div>
                                </div>

                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label for="shipping_area_name" class="control-label Validform_label" >续重每                       <select name="config[second_weight]">
                                            <option value="500">500</option>
                                            <option value="1000">1000</option>
                                            <option value="1500">1500</option>
                                            <option value="2000">2000</option>
                                            <option value="2500">2500</option>
                                            <option value="3000">3000</option>
                                            <option value="3500">3500</option>
                                            <option value="4000">4000</option>
                                            <option value="4500">4500</option>
                                            <option value="5000">5000</option>
                                            <option value="5500">5500</option>
                                            <option value="6000">6000</option>
                                            <option value="6500">6500</option>
                                            <option value="7000">7000</option>
                                            <option value="7500">7500</option>
                                        </select>克或其零数的费用</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="config[add_money]" class="form-control" name="config[add_money]" placeholder="请输入续重费用" value="<?=$model['config']['add_money']?>" datatype="n" errormsg="续重费用必须是数字类型">
                                        <div class="help-block">单位：元</div>
                                    </div>
                                </div>


                                <?php if($model['is_default'] == 0){ ?>
                                <div class="form-group clearfix">
                                    <div class='col-sm-2 text-right'>
                                        <label for="config" class="control-label Validform_label" >配送区域</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <div id="area_list">
                                            <?php if(!empty($area_list)){ foreach($area_list as $k=>$v){?>
                                                <label style="margin-left:10px;"><input class="area_list" type="checkbox" checked="checked" name="area_list[]" value="<?=$v['region_id']?>"><?=$v['name']?></label>
                                            <?php }}?>
                                        </div>


                                        <div class="help-block"></div>
                                    </div>

                                </div>

                                <div class="form-group required" >
                                    <div class="col-sm-2 text-right">
                                        <label class="control-label Validform_label">配送区域名称                                                     </label>
                                    </div>

                                    <div class="col-sm-10">
                                        <div class="province_id">
                                            <select id="province" size="10">
                                                <option value="0">请选择省份</option>
                                                <?php if(!empty($province)){ foreach($province as $k=>$v){?>
                                                <option value="<?=$v['id']?>"><?=$v['name']?></option>
                                                <?php }} ?>
                                            </select>

                                            <button onclick="addArea()" class="btn btn-default btn-sm" type="button" style="position:absolute;top:35%;margin-left:20px;">
                                                <i class="ace-icon fa fa-plus bigger-110"></i>
                                            </button>
                                        </div>
                                        <div class="help-block"></div>
                                    </div>
                                </div>

                                <?php } ?>

                            </div>
                            <div class="box-footer text-center">
                                <button class="btn btn-primary" type="submit">保存</button>
                                <span class="btn btn-white" onclick="history.go(-1)">返回</span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
{/block}

{block name="js"}
<script>

    var validate = validator('#pt_form',"<?=url('seller/ShippingArea/index',['shipping_id'=>$model['shipping_id']])?>");
    
</script>

<script>
    //添加配送区域
    function addArea(){
        //
        var province = $("#province").val(); // 省份
        var city = $("#city").val();        // 城市
        var district = $("#district").val(); // 县镇
        var text = '';  // 中文文本
        var tpl = ''; // 输入框 html
        var is_set = 0; // 是否已经设置了

        // 设置 县镇
        if(district > 0){
            text = $("#district").find('option:selected').text();
            tpl = '<input class="area_list" type="checkbox" checked name="area_list[]" value="'+district+'">'+text;
            is_set = district; // 街道设置了不再设置市
        }
        // 如果县镇没设置 就获取城市
        if(is_set == 0 && city > 0){
            text = $("#city").find('option:selected').text();
            tpl = '<input class="area_list" type="checkbox" checked name="area_list[]" value="'+city+'">'+text;
            is_set = city;  // 市区设置了不再设省份

        }
        // 如果城市没设置  就获取省份
        if(is_set == 0 && province > 0){
            text = $("#province").find('option:selected').text();
            tpl = '<label style="margin-left:10px;"><input class="area_list" type="checkbox" checked name="area_list[]" value="'+province+'">'+text+'</label>';
            is_set = province;

        }

        var obj = $("input[class='area_list']"); // 已经设置好的复选框拿出来
        var exist = 0;  // 表示下拉框选择的 是否已经存在于复选框中
        $(obj).each(function(){
            if($(this).val() == is_set){  //当前下拉框的如果已经存在于 复选框 中
                layer.alert('已经存在该区域', {icon: 2});  // alert("已经存在该区域");
                exist = 1; // 标识已经存在
            }
        })
        if(!exist)
            $('#area_list').append(tpl); // 不存在就追加进 去
    }
</script>


{/block}